package com.cy.pj.web配置类和控制层.controller;

import com.cy.pj.common.pojo.JsonResult;
import com.cy.pj.common.pojo.SysRole;
import com.cy.pj.common.util工具类设计.PageUtil封装开启分页;
import com.cy.pj.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role/")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;

    @GetMapping("checkRoles")
    public JsonResult findCheckRoles(){
        return new JsonResult(sysRoleService.findCheckRoles());
    }

    @PutMapping
    public JsonResult doUpdateRole(@RequestBody SysRole sysRole) {
        return new JsonResult(sysRoleService.updateRole(sysRole));
    }

    @PostMapping
    public JsonResult doSaveRole(@RequestBody SysRole sysRole){
        sysRoleService.saveRole(sysRole);
        return new JsonResult("save OK");
    }

    @GetMapping("{id}")
    public JsonResult doselectById(@PathVariable Integer id){
        return new JsonResult(sysRoleService.findById(id));

    }

    @GetMapping
   //模糊查询: http://localhost/role/?name=程序
public JsonResult dofindselect(SysRole sysRole){
    return new JsonResult(PageUtil封装开启分页.startPage().doSelectPage(()->{
    sysRoleService.findRoles(sysRole);}
    ));
//return new JsonResult(()->{sysRoleService.findRoles(sysRole);})
}
}
